<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--IOS HTML5页面中数字自动变蓝并识别为手机号-->
    <meta name="format-detection" content="telephone=no">
    <title>学生通行码</title>
    <script src="https://cdn.jsdelivr.net/npm/davidshimjs-qrcodejs@0.0.2/qrcode.min.js"></script>
    <style>
        html,body{
          height: 100%;
          margin: 0;
          background-color: #F8F8F8;
        }
        .bg {
          background-color: #3872EE;
          height: 24.5%;
        }
        .date {
            text-align: center;
        }
        .code-box-wrap {
          height: 75%;
          width: 100%;
          /* margin: 54px; */
          /* border-radius: 5px; */
          /* position: absolute; */
          margin-top: -160px;
          /* top: 30px; */
          /* top: 0; */
          /* background-color: yellow; */
          box-sizing: border-box;
          /* 三个值，考虑对称（上 左右 下）*/
          /* padding: 30px 30px 0;  */
          padding: 20px 25px 0;
        }
        .code-area {
          height: 100%;
          overflow: hidden;
          border-radius: 5px;
          background: white;
        }
        .date {
            margin: 12px 0 12px;
        }
        #clock {
          line-height: .8;
        }
        .code-real-time {
          font-size: 42px;
          line-height: 1;
          font-weight: bold;
          margin: 0;
        }
        .clock {
          line-height: .8;
        }
        .ps-info {
          width: calc(100%-16)px;
          /* padding: 5px; */
          /* margin: 10px; */
          margin: 0 8px;
          font-size: 16px;
          border-top: 1px solid #FAFAFA;
          display: flex;
          /* flex: 1; */
          justify-content: space-between;
        }
        .person {
          /* display: flex;
          */
          text-align: center;
          font-size: 16px;
          margin-top: 10px;
        }
        .person .button {
          margin-left: 10px;
          color: #3871C9;
        }
        #qrcode {
          margin-top: 5px;
          display: flex;
          justify-content: center;
        }
        .effect-time {
            margin: 5px 0 0 30px;
        }
        .info-card {
            margin-left: 40px;
        }
        .info-card .type {
            color: #b7b2b2;
        }
        .info-card p {
            margin: 8px;
        }
        .footer {
          color: #3871C9;
          font-size: 18px;
          text-align: center;
          /* margin-top: 10px; */
          margin-top: 20px;
        }
        .footer .sep {
            color: #b7b2b2;
        }
    </style>
</head>
<body>
  <div class="bg"></div>
  <div class="code-box-wrap">
    <div class="code-area">
      <div class="date">
        <p id= 'day' class="code-real-time">1月25日</p>
        <p id= 'clock' class="code-real-time">00:00:00</p>
      </div>
      <div class="ps-info">
        <span>经济管理学院</span>
        <span>2017339901246</span>
      </div>
      <!-- <qr-dropzone/> -->
      <div id="qrcode"></div>
      <div class="person">
        <span id="name">肖晶晶</span>
        <span class="button" id="refresh">刷新</span>
      </div>
    </div>
  </div>
    <p class="effect-time" >2021-02-28 至 <span id="effectTime">2021-07-03</span></p>
    <div class="info-card">
        <p><span class="type">通行码类型: </span><span>临时通行码</span></p>
        <p><span class="type">剩余次数: </span><span>9983</span></p>
        <p><span class="type">第一次刷卡时间: </span><span>2021-03-15 18:17:33</span></p>
    </div>
    <p class="footer">
        <span>通行记录</span>
        <span class="sep">|</span>
        <span>普通码</span>
    </p>
<script type="text/javascript">
    function wrapTime (str) {
        str = String(str)
        if (str.length < 2) return '0' + str
        return str
    }
    setInterval(() => {
        const date = new Date()
        const dayStr = (date.getMonth()+1) + '月' + date.getDate() + '日'
        const timeStr = wrapTime(date.getHours()) + ':' + wrapTime(date.getMinutes()) + ':' + wrapTime(date.getSeconds())
        document.getElementById('day').innerText = dayStr
        document.getElementById('clock').innerText = timeStr
        document.getElementById('effectTime').innerText = date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate()
    },1000)
    qrcodeSource = ['ifjahgjahsjfhdjkshajkhgjdshajkhjkgfjdskajfkladsajkfj', 'lovedfjakdsjfkldjaskfjkldajlkfjadskljfkfdsafdsfdsa', 'jingjingdanfnklasdjfkjasdkljfklsdajkljflkdsjafdsafds']
    const qrcodeOption = {
        text: qrcodeSource[Math.floor(Math.random()*qrcodeSource.length)],
        width: 280,
        height: 280,
        colorDark : '#3974F4',
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    }
    var qrcode = new QRCode(document.getElementById("qrcode"), qrcodeOption);
    document.getElementById('refresh').addEventListener('click', () => {
      qrcode.clear()
      qrcode.makeCode(qrcodeSource[Math.floor(Math.random()*qrcodeSource.length)])
    })
</script>
</body>
</html>